package Algorithm.ByteOpration;

//https://leetcode-cn.com/problems/maximum-product-of-word-lengths/
public class Leetcode318 {
    class Solution {
        public int maxProduct(String[] words) {
            int[] mask = new int[words.length];

            for(int i=0;i<words.length;i++){
                int temp = 0;
                for(int j=0;j<words[i].length();j++){
                    temp |= (1<<(words[i].charAt(j)-'a'));
                }
                mask[i] = temp;
            }

            int max = 0;
            for(int i=0;i<words.length;i++){
                for(int j=i+1;j<words.length;j++){
                    if((mask[i] & mask[j]) == 0){
                        if((words[i].length()*words[j].length()) > max){
                            max = words[i].length() * words[j].length();
                        }
                    }
                }
            }

            return max;
        }
    }
}
